home *** CD-ROM | disk | FTP | other *** search
- #include <Traps.h>
- #include <GenericPatch.h>
- #include <OSUtils.h>
- #include <stddef.h>
- #include <Extension.h>
- #include <Utils.h>
- #include <Exceptions.h>
- #include "Patches.h"
-
- typedef enum {
- eInitialClick,
- eFirstMouseUp,
- eSecondClick,
- eSecondMouseUp
- } ClickSet;
-
- static PostEventPatch *thePostEventPatch;
- static ButtonPatch *theButtonPatch;
- static Point theLastMouse;
- static ClickSet theClick;
- static long theLastTime;
- static short theMenuSelect;
- static Rect theMenuBarRect;
- Point Mouse : 0x830;
-
- static Boolean IsTimely(long lastTime)
- {
- return (Ticks - (DoubleTime >> 1)) <= lastTime;
- }
-
- static Boolean IsAround(Point p1, Point p2)
- {
- Rect r1, r2, rToss;
-
- r1.top = p1.v - 2;
- r1.bottom = p1.v + 2;
- r1.left = p1.h - 2;
- r1.right = p1.h + 2;
-
- r2.top = p2.v - 2;
- r2.bottom = p2.v + 2;
- r2.left = p2.h - 2;
- r2.right = p2.h + 2;
-
- return SectRect(&r1, &r2, &rToss);
- }
-
- static Boolean MouseInMenubar()
- {
- return PtInRect(Mouse, &theMenuBarRect);
- }
-
- /******************************************************************************************/
-
- ButtonPatch::ButtonPatch()
- {
- GenericPatch::InitGenericPatch(_Button, offsetof(ButtonPatchParms, itsResult));
- Install();
- Disable();
- }
-
- void ButtonPatch::Behavior()
- {
- reg ButtonPatchParms *parms = (ButtonPatchParms *) itsFrame->parameters;
- parms->itsResult = -1;
- AbortTrap();
- }
-
- /******************************************************************************************/
-
- PostEventPatch::PostEventPatch()
- {
- GenericPatch::InitGenericPatch(_PostEvent, 0);
- Install();
- }
-
- void PostEventPatch::Behavior()
- {
- Disable();
-
- switch ((short) itsFrame->ra0) {
- case mouseUp:
- if ((theClick == eFirstMouseUp)
- && IsAround(Mouse, theLastMouse)
- && IsTimely(theLastTime)
- && ((theMenuSelect > 0) || MouseInMenubar())) {
- theButtonPatch->Enable();
- AbortTrap();
- itsFrame->rd0 = noErr;
- theClick = eSecondClick;
- } else {
- theClick = eInitialClick;
- }
- theLastMouse = Mouse;
- break;
-
- case mouseDown:
- if (theClick == eInitialClick)
- theClick = eFirstMouseUp;
- else if (theClick == eSecondClick) {
- AbortTrap();
- itsFrame->rd0 = noErr;
- theButtonPatch->Disable();
- theClick = eInitialClick;
- }
- theLastTime = Ticks;
- theLastMouse = Mouse;
- break;
- }
-
- Enable();
- }
-
- /******************************************************************************************/
- #if 0
- MenuSelectPatch::MenuSelectPatch()
- {
- GenericPatch::InitGenericPatch(_MenuSelect, offsetof(MenuSelectParameters, itsResult));
- Install();
- }
-
- void MenuSelectPatch::Behavior()
- {
- reg MenuSelectParameters* params = (MenuSelectParameters*)itsFrame->parameters;
- reg MenuSelectProcPtr oldMenuSelect = (MenuSelectProcPtr) itsOld;
-
- theMenuSelect++;
-
- params->itsResult = (*oldMenuSelect)(params->itsStartPt);
- AbortTrap();
-
- theMenuSelect--;
- }
- #endif
-
- /******************************************************************************************/
- #if 1
- PopupMenuSelectPatch::PopupMenuSelectPatch()
- {
- GenericPatch::InitGenericPatch(_PopUpMenuSelect, offsetof(PopupMenuSelectParameters, itsResult));
- Install();
- }
-
- void PopupMenuSelectPatch::Behavior()
- {
- reg PopupMenuSelectParameters* params = (PopupMenuSelectParameters*)itsFrame->parameters;
- reg PopupMenuSelectProcPtr oldMenuSelect = (PopupMenuSelectProcPtr) itsOld;
-
- theMenuSelect++;
-
- params->itsResult = (*oldMenuSelect)(params->itsMenuHandle, params->itsTop, params->itsLeft, params->itsItem);
- AbortTrap();
-
- theMenuSelect--;
- }
- #endif
-
- /******************************************************************************************/
- void Install()
- {
- theClick = eInitialClick;
- theMenuSelect = 0;
-
- try {
- if (true
- && ((thePostEventPatch = new PostEventPatch) != nil)
- && ((theButtonPatch = new ButtonPatch) != nil)
- // && (new MenuSelectPatch != nil)
- && (new PopupMenuSelectPatch != nil)
- ) {
- // if extension succeeds, show happy icon.
- SysEnvRec environment; // machine configuration.
-
- // find out what kind of machine this is.
- SysEnvirons(curSysEnvVers, &environment);
-
- if (environment.hasColorQD && MainDevice)
- theMenuBarRect = (**MainDevice).gdRect;
- else {
- theMenuBarRect = _qd.screenBits.bounds;
- }
-
- theMenuBarRect.bottom = theMenuBarRect.top + 0x14;
-
- ShowIconFamily(128);
- } else {
- throw(memFullErr);
- }
- } /* try */
-
- catch {
- // extension failed, show sad icon.
- ShowIconFamily(129);
- throw(theException);
- }
- }
-
- // called when system is shutdown.
-
- void Remove()
- {
- Patch::RemoveAll();
- }
-